package cn.kgc.tangcco.action;

import cn.kgc.tangcco.model.PageParam;
import cn.kgc.tangcco.model.ResponseText;
import cn.kgc.tangcco.pojo.Clazz;
import cn.kgc.tangcco.pojo.Student;
import cn.kgc.tangcco.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 李昊哲
 * @Description
 * @create 2021/1/12 14:48
 */
@RestController
@RequestMapping(value = "/student")
public class StudentAction {
    @Autowired
    private StudentService studentService;

    @GetMapping(value = "/findOne")
    public ResponseText<Student> findOne(Integer id) {
        return studentService.findOne(id);
    }

    @GetMapping(value = "/getOne")
    public ResponseText<Student> getOne(Integer id) {
        return studentService.getOne(id);
    }

    @GetMapping(value = "/selectOne")
    public ResponseText<Student> selectOne(Integer id) {
        return studentService.getOne(id);
    }

    @GetMapping(value = "/findLike")
    public ResponseText<List<Student>> findLike(String firstName) {
        return studentService.findLike(firstName);
    }

    @PutMapping(value = "/update")
    public ResponseText<Student> update(Student student) {
        return studentService.update(student);
    }

    @PostMapping(value = "/nativeQuery")
    public ResponseText<List<Student>> nativeQuery(Student student) {
        return studentService.nativeQuery(student);
    }

    @PostMapping(value = "/loginByMobileAndAuthText")
    public ResponseText<Student> loginByMobileAndAuthText(Student student) {
        return studentService.loginByMobileAndAuthText(student);
    }

    @GetMapping(value = "/specificationLike")
    public ResponseText<List<Student>> specificationLike(String firstName) {
        return studentService.specificationLike(firstName);
    }

    @PostMapping(value = "/page")
    public Page<Student> page(Student student,
                              @RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
                              @RequestParam(value = "limit", required = false, defaultValue = "5") Integer limit) {
        return studentService.page(student, new PageParam(page, limit));
    }
}
